﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace MainJumpFleet.SteerBehaviors
{
   public  class newWander : seekWithInternalTarget
    {
       public float volatility;

      public float turnSpeed;
       Random r = new Random();
       public override void UpdateSteering(OakEngine.AI.Steering.Oak_Steering steer)
       {
           if (OakEngine.AI.Tools.OAK_AITools.SquareMagnitude(m_Target) == 0.0f)
           {
               InternalTarget = m_Agent.Position;
               InternalTarget += new Vector2(volatility, volatility);
           }

           float angle;
           Vector2 offset = m_Target - m_Agent.Position;
           if (OakEngine.AI.Tools.OAK_AITools.SquareMagnitude(offset) > 0)
           {
               angle = (float)Math.Atan2(offset.Y, offset.X);
           }
           else
               angle = 0;

           InternalTarget = m_Agent.Position;
           InternalTarget.X += volatility *(float) Math.Cos(angle);
           InternalTarget.Y += volatility *(float) Math.Sin(angle);

           InternalTarget.X += MathHelper.Lerp(-turnSpeed, turnSpeed, (float)r.NextDouble());
           InternalTarget.Y += MathHelper.Lerp(-turnSpeed, turnSpeed, (float)r.NextDouble());

           INTERNALTARGET = InternalTarget;

           base.UpdateSteering(steer);
       }
    }
}
